/*
 * Course:        COMP 380
 * Semester:      Summer 2012
 * Assignment:    Text To Speech
 * File Name:     MyBaseAdapter.java
 * Author:        James Paul Pan
 * 				  Kenneth Wakeland
 * 				  Peter Xaymountry
 * Group #:		  Group #3
 */

package com.comp380.texttospeech;

import java.util.ArrayList; 

import com.comp380.texttospeech.R; 
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

/*
 * This class take a list(or Array), then it get constructed and create
 * the contents of the view in your View.
 */
public class MyBaseAdapter extends BaseAdapter 
{   
	// Initialize the ArrayList variable.
	private static ArrayList<FileInformation> fileArrayList;
	
	// Initialize a LayoutInflater variable that instantiate layout
	// in XML file into the corresponding View object.
	private LayoutInflater mInflater;
	
	/*
	 * This method is a constructor that create an array of file and create a layout.
	 * 
	 * @ context
	 *  The context being pass in.
	 *  
	 * @ file_info
	 *  The arraylist being pass in.
	 */
	public MyBaseAdapter(Context context, ArrayList<FileInformation> file_info) 
	{        
		fileArrayList = file_info;        
		mInflater = LayoutInflater.from(context);    
	}
	
	/*
	 * This method get the folder size.
	 */
	public int getCount() 
	{   
		// Return the size of the list.
		return fileArrayList.size();    
	}
	
	/*
	 * THis method get the item at a certain position.
	 * 
	 * @ param position
	 * 	The position of the item the user want.
	 */
	public Object getItem(int position) 
	{        
		return fileArrayList.get(position);    
	}
	
	/*
	 * This method get the item ID at a certain position.
	 * 
	 * @param
	 * 	The position of the item ID the user want.
	 */
	public long getItemId(int position) 
	{        
		return position;    
	}
	
	/*
	 * This method returns the view of the folder and its files.
	 * 
	 * @param position
	 * 	The position of the file.
	 * 
	 * @param convertView
	 * 	The new view group.
	 * 
	 * @param parent
	 *  The parent view group.
	 */
	public View getView(int position, View convertView, ViewGroup parent) 
	{        
		ViewHolder holder;        
		if(convertView == null) 
		{
			convertView = mInflater.inflate(R.layout.custom_row_view, null);
			holder = new ViewHolder();
			holder.txtPrevName = (TextView) convertView.findViewById(R.id.PrevName);
			convertView.setTag(holder);
		} 
		else 
		{
			holder = (ViewHolder) convertView.getTag();
		}
		
		// Set the Text of the previous name.
		holder.txtPrevName.setText(fileArrayList.get(position).getPrevName());
		
		return convertView;
	}
	
	/*
	 * This class create a textview variable.
	 */
	static class ViewHolder 
	{        
		TextView txtPrevName;                
	}

}
